package org.xiaoyu.rpc;

import io.netty.channel.Channel;
import org.xiaoyu.rpc.common.extension.ExtensionLoader;
import org.xiaoyu.rpc.protocol.Protocol;
import org.xiaoyu.rpc.remoting.RequestHandler;
import org.xiaoyu.rpc.remoting.packet.Invocation;
import org.xiaoyu.rpc.remoting.packet.Result;

/**
 * Created By Have
 * 2021/7/13 15:35
 */
public class RpcRequestHandler implements RequestHandler {
    private static final Protocol protocol = ExtensionLoader.getExtensionLoader(Protocol.class).getDefaultExtension();

    @Override
    public Result handle(Channel channel, Invocation invocation) {
        Invoker<?> invoker = protocol.getInvoker(channel, invocation);
        return invoker.invoke(invocation);
    }
}
